package 多线程.CompletableFuture异步编排;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * CompletableFuture 提供了四个静态方法来创建一个异步操作
 *
 * 1 #runAsync 无返回值
 * 2 public static CompletableFuture<Void> runAsync(Runable runable)
 * 3 public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor)
 * 4
 * 5 #supplyAsync 有返回值
 * 6 public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier)
 * 7 public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor)
 */
public class ThreadTestAsyn1 {

    //创建线程池
    public static ExecutorService executor = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws Exception {
        //1、Async创建异步对象，没返回值
         CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            //异步任务内容
             System.out.println("current thread: " + Thread.currentThread().getId());
             int i = 10 / 2;
           System.out.println("run result: " + i);
         }, executor);
         System.out.println("main...end..");
     }
}